package jpao.benchmark.metric;

import org.junit.AfterClass;
import org.junit.Test;
import static org.junit.Assert.*;
import org.junit.BeforeClass;

/**
 *
 * @author soa
 */
public class GivenMetricConverter {
    
    public GivenMetricConverter() {
    }

    @BeforeClass
    public static void setUpClass() throws Exception {
    }

    @AfterClass
    public static void tearDownClass() throws Exception {
    }

    @Test
    public void whenYouConvertNanoToMicroSecondThenErrorOccursIfUnitIsNotNano() {
        Metric metric = new Metric(10, Unit.SECOND_UNIT);
        try {
            MetricConverter.convertNanosecondToMicrosecond(metric);
            fail("IllegalArgumentException should occurs !");
        } catch (IllegalArgumentException e) {
            System.out.println(e.getMessage());
        }
    }
    
    @Test
    public void whenYouConvert20000NanoToMicroSecondThenYouShouldHave20Microseconds() {
        
        Metric metric = new Metric(20000, Unit.NANOSECOND_UNIT);
        Metric microsecondMetric = MetricConverter.convertNanosecondToMicrosecond(metric);
        assertNotNull(microsecondMetric);
        assertEquals(20, microsecondMetric.getMeasure(), 0);
        assertEquals(Unit.MICROSECOND_UNIT, microsecondMetric.getUnit());
    }
}
